<template>
	<view>
		<view style=" z-index: 1000;background-color: white; width: 100%;"></view>
		<view class="header-max">
			<view class="header-max-content">
				<image @tap="back" src="@/static/images/xiangzuo.png" mode="widthFix" class="back"></image>
				<view class="title">{{title}}</view>
				<!-- #ifndef MP-WEIXIN -->
				<view class="publish" @tap="public">发布</view>
				<!-- #endif -->
			</view>
		</view>
		<view style="height: 190rpx;"></view>
		<view class="header-search">
			<view class="input">
				<image src="@/static/images/sousuo1.png" class="search-icon" mode="widthFix"></image>
				<input class="search-text" type="text" placeholder="请输入关键字" v-model="keyword">
				<view class="search-btn" @tap="getSearchRes">搜索</view>
			</view>
		</view>
		<view style="height: 20rpx;"></view>

		<view class="item-data">
			<view class="data" @tap="certificateDetail(item.id)" v-for="(item,index) in lists" :key="index">
				<view class="item-data-title">
				{{item.title}}（
				<text v-if="item.type == 1">岗前</text>
				<text v-if="item.type == 2">就业</text>）
				</view>
				<view class="item-data-detail">{{item.content}}</view>
				<view class="item-data-bottom">
					<view class="item-data-bottom-left">
						{{item.created_at}}
					</view>
					<view class="item-data-bottom-right">
						<image src="/static/images/place.png" mode=""
							style="height: 28rpx;width: 26rpx;margin-right: 14rpx;"></image>
						<text>{{item.location}}</text>
					</view>
				</view>
			</view>
		</view>
		<view style="height: 30rpx;"></view>
		<uni-load-more :status="loadingType"></uni-load-more>
	</view>
</template>

<script>
	import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
	export default {
		components: {
			uniLoadMore
		},
		data() {
			return {
				title: '智慧培训',
				keyword: '',
				page: 1,
				lists: [],
				loadingType: 'more',
			}
		},

		onLoad: function() {

			uni.showLoading({
				title: '加载中...'
			});

			this.loadData();
			setTimeout(() => {
				this.isLoaded = true;
				uni.hideLoading();
			}, 600)

		},

		methods: {
			back() {
				uni.navigateTo({
					url: '/pages7/pages/index/index'
				})
			},

			public() {
				let url = '/pages7/pages/nimble/certificate_publish';

				uni.navigateTo({
					url: url
				})
			},

			async loadData(type = 'add') {
				//这里是将订单挂载到tab列表下
				if ((this.loadingType === 'loading' || this.loadingType === 'noMore') && type == 'add') {
					//防止重复加载
					return;
				}

				this.loadingType = 'loading';

				let dataObj = {
					page: this.page,
					keyword: this.keyword
				}
				let url = '/certificate_list';

				let ldata = await this.$myRequest({
					url: url,
					data: dataObj,
					methods: 'post'
				})

				let ndata = ldata.data.data.list;
				if (ndata.length > 0) {
					this.lists = [...this.lists, ...ndata];
					let count = ldata.data.data.totalList;
					if (ndata.length >= count) {
						this.page = this.page + 1;
						this.loadingType = 'more';
					} else {
						this.loadingType = 'noMore';
					}
				} else {
					this.loadingType = 'noMore';
				}
			},

			getSearchRes() {
				this.lists = [];
				this.page = 1;
				this.loadingType = 'more';

				this.loadData('refresh')
			},

			certificateDetail(id) {
				uni.navigateTo({
					url: '/pages7/pages/nimble/certificate_detail?id=' + id
				})
			},
		}
	}
</script>

<style lang="scss">
	.header-max {
		display: flex;
		align-items: center;
		background-color: white;
		position: fixed;
		width: 100%;
		height: 180rpx;
		z-index: 1000;

		.header-max-content {
			width: 100%;
			display: flex;
			justify-content: space-between;
			position: absolute;
			top: 50px;
			padding: 0 30upx;

			.back {
				width: 17rpx;
				height: 30rpx;
				margin-left: 30rpx;
				position: absolute;
			}

			.title {
				margin-left: 40%;
				letter-spacing: 2rpx;
				font-size: 30rpx
			}
		}
	}

	.publish {
		position: absolute;
		right: 30upx;
		font-size: 30upx;
		letter-spacing: 4upx;
		color: white;
		background-color: $base-color;
		border-radius: 50upx;
		padding: 10upx;
	}

	.header-search {
		.input {
			display: flex;
			background-color: white;
			width: 710rpx;
			height: 80rpx;
			padding: 10rpx;
			border: 3rpx solid #f3511a;
			border-radius: 100rpx;
			align-items: center;
			margin: 0rpx auto;
			// margin-bottom: 25rpx;

			.search-text {
				flex: 1;
				color: #6d6e6e;
				font-size: 28rpx;
			}

			.search-btn {
				font-size: 30rpx;
				background-color: #f3511a;
				color: white;
				width: 110rpx;
				letter-spacing: 2rpx;
				height: 57rpx;
				line-height: 57rpx;
				text-align: center;
				border-radius: 50rpx;
			}

			.search-icon {
				width: 25rpx;
				height: 25rpx;
				margin: 0 10rpx;
			}
		}

	}

	.center {
		display: grid;
		grid-template-columns: repeat(4, 195rpx);
		grid-gap: 30rpx 0;

		.center-item {
			display: flex;
			// text-align: center;
			align-items: center;
			justify-content: center;

			.center-icon {
				margin-left: 10rpx;
				width: 14rpx;
				height: 8rpx;
			}
		}

	}

	.item-data {
		// text-align: center;
		display: grid;
		// grid-template-columns: repeat(2, 340rpx);
		// grid-template-rows: repeat(2, 540rpx);
		grid-gap: 30rpx;
		margin-left: 24rpx;
		margin-right: 24rpx;

		// position: relative;
		.location {
			position: absolute;
			// bottom: 10rpx;
			top: 310rpx;
			left: 20rpx;
			display: flex;
			align-items: center;
		}

		.location-text {
			margin-left: 10rpx;
			color: white;
			font-size: 26rpx
		}

		.location-img {
			width: 23rpx;
			height: 26rpx;
		}

		.data {
			box-shadow: 5rpx 5rpx 15rpx #c4c4c7;
			border-radius: 20rpx;
			position: relative;


		}

		.item-data-title {
			padding: 30upx;
			font-size: 30upx;
		}

		.item-data-detail {
			line-height: 48upx;
			padding: 0 30upx 22upx;
			font-size: 28upx;
		}

		.item-data-bottom {
			border-top: 2upx solid #ebebeb;
			height: 82upx;
			padding: 0 30upx;
			font-size: 28upx;
			display: flex;
			align-items: center;
			justify-content: space-between;
		}

		.item-data-bottom-right {
			display: flex;
			align-items: center;
		}
	}
</style>